#include "Goal.h"

Goal::Goal(void) : m_score(0)
{
}
Goal::Goal(Region* field, Location location) : m_score(0), m_location(location)
{
	m_width = 20.0f;
	m_height = 60.0f;

	if(location == left)
	{
		m_top = field->Center().y - m_height/2, //top
		m_left = field->Left() - m_width, //left
		m_bottom = field->Center().y + m_height/2, //bottom
		m_right = field->Left(),// - 1.0f, //right
		m_id = -2;
		m_leftPost = Vector2(m_right, m_top);
		m_rightPost = Vector2(m_right, m_bottom);
	}
	else
	{
		m_top = field->Center().y - m_height/2, //top
		m_left = field->Right(),// + 1.0f, //left
		m_bottom = field->Center().y + m_height/2, //bottom
		m_right = field->Right() + m_width, //right
		m_id = -3;
		m_leftPost = Vector2(m_left, m_bottom);
		m_rightPost = Vector2(m_left, m_top);
	}

	m_center = Vector2( (m_left + m_right)*0.5f, (m_top + m_bottom)*0.5f );
}
Goal::~Goal(void)
{
}
bool Goal::IsGoalScored(Vector2 ballPos)
{
	if(Inside(ballPos))
	{
		m_score++;
		return true;
	}
	return false;
}

Vector2 Goal::GetFirstPost(Vector2 from) const
{
	if (from.y <= m_center.y)
		if (m_location == left)
			return m_leftPost;
		else
			return m_rightPost;
	else
		if (m_location == right)
			return m_leftPost;
		else
			return m_rightPost;
	return Vector2::ZERO;
}

Vector2 Goal::GetSecondPost(Vector2 from) const
{
	if (from.y <= m_center.y)
		if (m_location == right)
			return m_leftPost;
		else
			return m_rightPost;
	else
		if (m_location == left)
			return m_leftPost;
		else
			return m_rightPost;
	return Vector2::ZERO;
}